package rsa.min;

import java.math.BigInteger;

import rsa.lib.ExtendedEulid;
import rsa.lib.Key;
import rsa.lib.PrimeLib;

public class CreateKey {
	private BigInteger p;
	private BigInteger q;
	private BigInteger n;
	private BigInteger e;
	private BigInteger d;
	private Key publicKey;
	private Key privateKey;
	
	public CreateKey(int keylength){
		p = PrimeLib.createPrime(keylength, 100);
		q = PrimeLib.createPrime(keylength, 100);
		n = p.multiply(q);
		BigInteger phiN = (p.subtract(BigInteger.ONE)).multiply(q.subtract(BigInteger.ONE));
		e = new BigInteger("65537");
		d = ExtendedEulid.inverseModule(e, phiN);
		publicKey = new Key(e, n);
		privateKey = new Key(d, n);
	}
	
	public Key getPublicKey(){
		return publicKey;
	}
	
	public Key getPrivateKey(){
		return privateKey;
	}
}
